<?php

namespace app\service\logic\common\user;

use app\model\communal\UserExpertVisitModel;
use think\Model;
use app\service\logic\BaseService;

final class ExpertVisitService extends baseservice
{
    protected string $modelclassname = 'UserExpertVisitModel';

    /**
     * 关注/取消
     *
     * @param $params
     * @return bool|Model
     */
    public function create($params)
    {
        $result = false;
        $model = UserExpertVisitModel::withSearch(['user_id', 'expert_id'], $params)->findorempty();
        if ($model->isEmpty()) {
            // 未访问
            $result = $model->save($params);
        }

        return $result;
    }

    /**
     * 关注数量
     *
     * @param $expertId
     * @return int
     */
    public function getVisitNumberByExpertId($expertId)
    {
        return UserExpertVisitModel::where('expert_id', $expertId)->count();
    }
}
